/*
package com.budwk.app.ocr_general;


import jdk.jfr.Description;
import org.artofsolving.jodconverter.OfficeDocumentConverter;
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration;
import org.artofsolving.jodconverter.office.ExternalOfficeManagerConfiguration;
import org.artofsolving.jodconverter.office.OfficeException;
import org.artofsolving.jodconverter.office.OfficeManager;

import java.io.File;
import java.io.FileOutputStream;
import java.util.UUID;


*/
/*  @Author: Administrator
  @Description:
  @Date: 2022/9/27 17:22*//*





public class LibreOfficeAndJodconverter {
    private static OfficeManager officeManager = null;
    //private static final String dirPath = "C:\\Users\\CXB-WGW\\Desktop\\file\\pdf";
    private static final String dirPath = "/data/shequ/file/file/ocrFile/outPdf";

    //private static final String LibreOfficeDirPath = "C:\\Program Files\\LibreOffice";
    private static final String LibreOfficeDirPath = "/usr/lib64/libreoffice";

    public static void init() {
        try {
            System.out.println("尝试连接已启动的服务...");
            ExternalOfficeManagerConfiguration externalProcessOfficeManager = new ExternalOfficeManagerConfiguration();
            externalProcessOfficeManager.setConnectOnStart(true);
            externalProcessOfficeManager.setPortNumber(8100);
             officeManager = externalProcessOfficeManager.buildOfficeManager();
            LibreOfficeAndJodconverter.officeManager.start();
            System.out.println("转换服务启动成功!");
        } catch (Exception e) {
            //命令方式：soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
            System.out.println("启动新服务!");
            String libreOfficePath = LibreOfficeDirPath;
            // 此类在jodconverter-core中3版本中存在，在2.2.2版本中不存在
            DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
            // libreOffice的安装目录
            configuration.setOfficeHome(new File(libreOfficePath));
            // 设置端口号
            configuration.setPortNumber(8100);
            // 设置任务执行超时为5分钟
            configuration.setTaskExecutionTimeout(1000 * 60 * 5L);
            // 设置任务队列超时为24小时
            configuration.setTaskQueueTimeout(1000 * 60 * 60 * 24L);

            // 开启转换服务
            officeManager = configuration.buildOfficeManager();
            officeManager.start();
            System.out.println("服务启动成功!");
        }
    }
    public static void desory() {
        if (officeManager != null) {
            officeManager.stop();
        }
    }
// 合并多个PDF，注意，源pdf中不能含有目的pdf，否则将合并失败

*/
/**
     * 开启服务时耗时，需要安装
     * 并不是看到什么，就转化为什么样的。有偏移
     *
     * @param args*//*





    public static void main(String[] args) {

        init();
        task();
        desory();
    }
    public static void task() {
        String outputname = "output.pdf";
        doDocToFdpLibre("1.docx", outputname);

    }
    public static PathBean doDocToFdpLibre(String inputFileName, String outputFileName) throws OfficeException {
        File inputFile=null;
       String inPath= dirPath+File.separator+"outWord"+File.separator + inputFileName;
        String outPath= dirPath+File.separator+"outPdf"+File.separator + outputFileName;

        inputFile = new File(inPath);

        System.out.println("libreOffice开始转换..............................");
        Long startTime = System.currentTimeMillis();
        OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager);
        String s=dirPath+File.separator+"outPdf"+File.separator;
        File outputFile = new File(outPath);
        if (outputFile.exists()) {
//            String uuid1 = UUID.randomUUID().toString();
//            File temp1 = new File(s + uuid1 + ".pdf");
//            outputFile.renameTo(temp1);

            String uuid = UUID.randomUUID().toString();
            outputFileName= uuid + ".pdf";
            File temp2 = new File(s +outputFileName);
            converter.convert(inputFile, temp2);

//            String[] files = {s + uuid1 + ".pdf", s + uuid + ".pdf"};
//            String savepath = s + outputFileName;

//            if (mergePdfFiles(files, savepath)) {
//                temp1.delete();
//                temp2.delete();
//            }
        } else {
            converter.convert(inputFile, outputFile);
        }
        // 转换结束
        System.out.println("转换结束。。。。。");
        //转换时间
        long endTime = System.currentTimeMillis();
        long time = endTime - startTime;
        System.out.println("libreOffice转换所用时间为：" + time);

        return new PathBean(inPath,outPath);
    }


    public static PathBean doDocToFdpLibreOne(String inputFileName, String outputFileName) throws OfficeException {
        File inputFile=null;
        String inPath= dirPath+File.separator+"outWord"+File.separator + inputFileName;
        String outPath= dirPath+File.separator+"outPdf"+File.separator + outputFileName;

        inputFile = new File(inputFileName);

        System.out.println("libreOffice开始转换..............................");
        Long startTime = System.currentTimeMillis();
        OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager);
        String s=dirPath+File.separator+"outPdf"+File.separator;
        File outputFile = new File(outputFileName);
        if (outputFile.exists()) {
//            String uuid1 = UUID.randomUUID().toString();
//            File temp1 = new File(s + uuid1 + ".pdf");
//            outputFile.renameTo(temp1);

            String uuid = UUID.randomUUID().toString();
            outputFileName= uuid + ".pdf";
            File temp2 = new File(outputFileName);
            converter.convert(inputFile, temp2);

//            String[] files = {s + uuid1 + ".pdf", s + uuid + ".pdf"};
//            String savepath = s + outputFileName;

//            if (mergePdfFiles(files, savepath)) {
//                temp1.delete();
//                temp2.delete();
//            }
        } else {
            converter.convert(inputFile, outputFile);
        }
        // 转换结束
        System.out.println("转换结束。。。。。");
        //转换时间
        long endTime = System.currentTimeMillis();
        long time = endTime - startTime;
        System.out.println("libreOffice转换所用时间为：" + time);

        return new PathBean(inPath,outPath);
    }
}
*/
